//package com.ctl.utils.activemq;
//
//import org.apache.activemq.ActiveMQConnection;
//import org.apache.activemq.ActiveMQConnectionFactory;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import javax.jms.*;
//import java.util.concurrent.atomic.AtomicInteger;
///**
// * <p>Title: Comsumer</p>
// * <p>Description: </p>
// * <p>Copyright: Copyright (c) 2018</p>
// * <p>Company: www.hanshow.com</p>
// *
// * @author guolin
// * @version 1.0
// * @date 2019-03-02 18:40
// */
//public class Comsumer {
//    static Logger logger = LoggerFactory.getLogger(Comsumer.class);
//
//    private static final String USERNAME =ActiveMQConfig.USERNAME;// ActiveMQConnection.DEFAULT_USER;
//
//    private static final String PASSWORD = ActiveMQConfig.PASSWORD;// ActiveMQConnection.DEFAULT_PASSWORD;
//
//    private static final String BROKEN_URL = ActiveMQConfig.BROKEN_URL;// ActiveMQConnection.DEFAULT_BROKER_URL;
//
//    ConnectionFactory connectionFactory;
//
//    Connection connection;
//
//    Session session;
//
//    ThreadLocal<MessageConsumer> threadLocal = new ThreadLocal<>();
//    AtomicInteger count = new AtomicInteger();
//
//    public void init(){
//        try {
//            connectionFactory = new ActiveMQConnectionFactory(USERNAME,PASSWORD,BROKEN_URL);
//            connection  = connectionFactory.createConnection();
//            connection.start();
//            session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
//        } catch (JMSException e) {
//           logger.error("init fail",e);
//        }
//    }
//
//
//    public void getMessage(String disname){
//        try {
//            Queue queue = session.createQueue(disname);
//            MessageConsumer consumer = null;
//
//            if(threadLocal.get()!=null){
//                consumer = threadLocal.get();
//            }else{
//                consumer = session.createConsumer(queue);
//                threadLocal.set(consumer);
//            }
//            while(true){
//                Thread.sleep(1000);
//                TextMessage msg = (TextMessage) consumer.receive();
//                if(msg!=null) {
//                    msg.acknowledge();
//                    System.out.println(Thread.currentThread().getName()+": Consumer:我是消费者，我正在消费Msg"+msg.getText()+"--->"+count.getAndIncrement());
//                }else {
//                    break;
//                }
//            }
//        } catch (JMSException e) {
//            logger.error("JMSException",e);
//
//        } catch (InterruptedException e) {
//            logger.error("InterruptedException",e);
//
//        }
//    }
//}